package org.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.demo.entity.BackgroundCheck;

/**
 * 政审信息Mapper接口
 */
@Mapper
public interface BackgroundCheckMapper extends BaseMapper<BackgroundCheck> {
    
    /**
     * 根据申请人ID查询政审信息
     * @param applicantId 申请人ID
     * @return 政审信息
     */
    @Select("SELECT * FROM background_check WHERE applicant_id = #{applicantId}")
    BackgroundCheck selectByApplicantId(@Param("applicantId") Long applicantId);
    
    /**
     * 统计政审信息总数
     * @param name 申请人姓名，可为空
     * @param type 政审类型，可为空
     * @param result 政审结果，可为空
     * @return 总数
     */
    @Select("<script>"
            + "SELECT COUNT(*) FROM background_check "
            + "<where>"
            + "<if test='name != null and name != \"\"'> AND name LIKE CONCAT('%', #{name}, '%') </if>"
            + "<if test='type != null and type != \"\"'> AND type = #{type} </if>"
            + "<if test='result != null and result != \"\"'> AND result = #{result} </if>"
            + "</where>"
            + "</script>")
    int selectCount(@Param("name") String name, @Param("type") String type, @Param("result") String result);
} 